/*
 * @Author: yaoge233 1351192080@qq.com
 * @Date: 2024-12-23 00:18:14
 * @LastEditors: yaoge233 1351192080@qq.com
 * @LastEditTime: 2024-12-23 01:08:05
 * @FilePath: \react-learning\src\store\modules\counterStore.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createSlice } from "@reduxjs/toolkit"

const counterStore  = createSlice({
  name: 'counter',
  //初始状态数据state
  initialState: {
    count : 0
  },
  //修改数据的同步方法(支持直接修改)
  reducers:{
    increment(state){
      state.count++
    },
    decrement(state){
      state.count--
    },
    addToNumber(state,action){
      state.count = action.payload
    }
  }
})

//解构出创建action对象的函数(actionCreater)
const { increment, decrement, addToNumber } = counterStore.actions
//获取reducer函数
const counterReducer = counterStore.reducer
//导出创建action对象的函数和reducer函数
export { increment, decrement, addToNumber }
export default counterReducer